import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    name: 'LoginAdmin',
    component:()=> import(/* webpackChunkName: "LoginAdmin" */ '@/pages/LoginAdmin.vue'),
    meta:{title: '登录'}
  },
  {
    path: '/Home',
    name:'AdminHome',
    component:()=> import(/* webpackChunkName: "AdminHome" */ '@/pages/AdminHome.vue'),
    redirect:{path: '/Home/useressay'},
    children: [
      {
        path: 'useressay',
        name: 'useressay',
        component:()=> import(/* webpackChunkName: "useressay" */ '@/pages/UserEssay.vue'),
        props:true,
        meta:{title: '文章'}
      },
      {
        path: 'addessay',
        name: 'addessay',
        component:()=> import(/* webpackChunkName: "addessay" */ '@/pages/AddEssay.vue'),
        props:true,
        meta:{title: '添加'}
      },{
        path:'SelectLog',
        name: 'SelectLog',
        component: ()=>import(/* webpackChunkName: "SelectLog" */ '@/pages/SelectLog.vue'),
        meta:{title: '日志'}
      },{
        path:"FriendChain",
        name: 'FriendChain',
        component:()=>import(/* webpackChunkName: "FriendChain" */ '@/pages/FriendChain.vue'),
        meta:{title: '友链'}
      },{
        path:"AdminMessage",
        name: 'AdminMessage',
        component:()=>import(/* webpackChunkName: "AdminMessage" */'@/pages/AdminMessage.vue'),
        meta:{title: '留言'}
      }
    ]
  },
  {
    path:'/error',
    name:'error',
    component:()=> import(/* webpackChunkName: "error" */ '@/error/adminError.vue'),
    meta:{title: '404错误'}
  },
  {
    path: '/:pathMatch(.*)',
    redirect:'/error'
    
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

router.beforeEach((to,from,next)=>{
  document.title=<any>to.meta.title;
  next();
})

export default router
